package com.itheima.Service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.Service.CheckService;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckServiceImpl implements CheckService {
    @Autowired
    CheckItemMapper checkItemMapper;
    @Override
    public void add(CheckItem checkItem) {
    checkItemMapper.add(checkItem);

    }

    @Override
    public void delete(Integer id) {
        checkItemMapper.delete(id);
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemMapper.edit(checkItem);
    }

    @Override
    public PageResult findPage (QueryPageBean queryPageBean) throws IllegalAccessException {
        if(queryPageBean==null){
            throw new IllegalAccessException("queryPageBean cannot be null");
        }
        //todo
        // 之后要把分页查询的条件放进去
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<CheckItem> page=checkItemMapper.page();
        PageResult pageResult=new PageResult(page.getTotal(), page.getResult());
        return pageResult;
    }

    @Override
    public CheckItem findById(Integer id) {
        CheckItem checkItem= checkItemMapper.findById(id);
        return checkItem;
    }
}
